import ObservableObject from "../observer/observable.object"
import Color from "../three/Color"
import * as THREE from "three"
import geoFT from "../math/geoFT"
import { TagDescriptionChunkType } from "../enum/tagChunkType.enum"
export default class Mattertag extends ObservableObject {
  sid: string
  created: Date
  modified: Date
  enabled: boolean
  label: string
  description: string
  parsedDescription: any[]
  anchorPosition: THREE.Vector3
  anchorNormal: THREE.Vector3
  stemVector: THREE.Vector3
  stemHeight: number
  stemVisible: boolean
  color: THREE.Color
  mediaType: string
  mediaSrc: string
  widgetFrame: any
  floorId: string
  roomId: string
  constructor() {
    super()
    this.sid = ""
    this.created = new Date()
    this.modified = new Date()
    this.enabled = !0
    this.label = ""
    this.description = ""
    this.parsedDescription = []
    this.anchorPosition = new THREE.Vector3()
    this.anchorNormal = new THREE.Vector3(0, 1, 0)
    this.stemVector = new THREE.Vector3(0, 0, geoFT.getM(1))
    this.stemHeight = geoFT.getM(1)
    this.stemVisible = !0
    this.color = Color.MATTERTAG_BLUE.clone()
    this.mediaType = TagDescriptionChunkType.none
    this.mediaSrc = ""
    this.widgetFrame = null
  }
  copy(e: Mattertag) {
    this.anchorNormal.copy(e.anchorNormal)
    this.anchorPosition.copy(e.anchorPosition)
    this.color.copy(e.color)
    this.created.setTime(e.created.getTime())
    this.description = e.description
    this.enabled = e.enabled
    this.floorId = e.floorId
    this.roomId = e.roomId
    this.label = e.label
    this.mediaType = e.mediaType
    this.mediaSrc = e.mediaSrc
    this.modified.setTime(e.modified.getTime())
    this.sid = e.sid
    this.stemVector.copy(e.stemVector)
    this.stemHeight = e.stemHeight
    this.stemVisible = e.stemVisible
    this.parsedDescription = []
    for (const t of e.parsedDescription) {
      this.parsedDescription.push({
        link: t.link && {
          label: t.link.label.slice(),
          url: t.link.url.slice(),
          type: t.link.type,
          navigationData: t.link.navigationData && {
            floorVisibility: t.link.navigationData.floorVisibility,
            mode: t.link.navigationData.mode,
            sweepIndex: t.link.navigationData.sweepIndex,
            panoId: t.link.navigationData.panoId,
            position: t.link.navigationData.position && t.link.navigationData.position.clone(),
            quaternion: t.link.navigationData.quaternion.clone(),
            zoom: t.link.navigationData.zoom
          }
        },
        text: t.text,
        type: t.type
      })
    }

    this.copyWidgetFrame(e.widgetFrame)
    this.commit()
    return this
  }
  clone() {
    return new Mattertag().copy(this)
  }
  copyWidgetFrame(e) {
    if (e) {
      if (this.widgetFrame) {
        for (const n of ["width", "height"]) this.widgetFrame.size[n] = e.size[n]
        this.widgetFrame.frame = e.frame
      } else {
        this.widgetFrame = Object.assign({}, e)
      }
    } else {
      this.widgetFrame = null
    }
  }
}
